<!--
 * @Descripttion: 
 * @version: 
 * @Author: 彭勃
 * @Date: 
 * @LastEditors: sueRimn
 * @LastEditTime: 
-->
<template>
	<!-- 导出/下载模板 组件 -->
	<a-button 
		:type="type" 
		:size="size" 
		:loading="dwnLoading"
		plain
		@click="handleExport"
		icon="export"
		:disabled="dwnLoading"
	>
		{{ dwnLoading ? `正在导出...` : text }}
	</a-button>
</template>

<script>
export default {
	props:{
		type: {type: String,default: "danger"},  //type
		size: {type: String,default: "default"},  //size
		text: {type: String,default: "导出"},  //按钮上的文字
		title: {type: String,default: "默认标题"},  //导出文档的标题
		url: {type: String,default: ""},  			//接口url
		obj: {type: Object,default(){ return {} }},   //筛选字段
		header:{type: Boolean,default : false},
		isBody:{type: Boolean,default : false}
	},
	data(){
		return {
			dwnLoading: false,
		}
	},
	methods:{
		clearNull(obj) {
			Object.keys(obj).forEach(item => {
				if (obj[item] === '' || obj[item] === undefined || obj[item] === null || obj[item] === 'null') delete obj[item]
			})
			return obj
		},
		// 导出
		handleExport() {
			let query = this.clearNull({
				...this.obj
			})
      this.dwnLoading = true
      this.download(this.url, query, `${this.title}_${this.dayjs(new Date()).format('YYYY/MM/DD HH:mm:ss')}.xls`,this.header,this.isBody).then(res => {
        this.dwnLoading = false
				this.$emit('ok')
      })
    }
	},
};
</script>

<style lang="scss" scoped></style>
